#include "../wnds/head.h"
#include "../data_struct/head.h"
#include "../global/head.h"
#include "../macro/head.h"
#include "../msg/head.h"

int main( int argc, char *argv[] )
{
    using namespace sgsj_client;
    int ret = 0;

    if( 0 == ret )
    {
        g_pSysData = new sys_data;
        if( !g_pSysData )
        {
            ret = 1;
        }
    }

    if( 0 == ret )
    {
        ret = g_pSysData->init();
    }

    if( 0 == ret )
    {
        QApplication a( argc, argv );
        QTextCodec * textCodec = QTextCodec::codecForName( "System" );
        QTextCodec::setCodecForLocale( textCodec );
        QTranslator translator;
        if( 0 == ret )
        {
            char file[1024] = { 0 };
            g_pSysData->m_os.m_pCrt->strcpy( file, g_pSysData->m_szExePath );
            g_pSysData->m_os.m_pMisc->path_append( file, "res/learn_zh_CN.qm" );
            bool bRet = translator.load( file );
            if( bRet )
            {
                a.installTranslator( &translator );
            }
            else
            {
                ret = 1;
            }
        }
        if( 0 == ret )
        {
            login_dlg dlg;
            if( dlg.exec() != QDialog::Accepted )
            {
                ret = 1;
            }
        }
        if( 0 == ret )
        {
            main_wnd wnd;
            wnd.show();
            ret = a.exec();
        }
    }

    if( g_pSysData )
    {
        g_pSysData->term();
        delete g_pSysData;
        g_pSysData = 0;
    }

    return ret;
}

